use crate::base::Coord;
use crate::base::Grid;

pub fn check_coord_for_grid(grid: &Grid, coord: Coord) -> Result<(), String> {
    if !grid.is_valid_coord(coord) {
        return Err(format!("'{:?}' is not a valid coord", coord));
    }
    if grid.cell(coord).unwrap().is_routed() {
        return Err(format!("Coord '{:?}' has been used", coord));
    }
    Ok(())
}

pub fn check_routable(start: &Coord, target: &Coord, path_len: usize) -> bool {
    (path_len - start.manhattan_distance(target) as usize) % 2 == 1
}